<template>
  <el-dialog title="编辑流程" :visible.sync="dialogVisible" width="30%" :append-to-body="true">
    <el-form ref="editForm" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="流程ID" prop="value">
        <el-input v-model="form.value"></el-input>
      </el-form-item>
      <el-form-item label="流程名称" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <el-form-item label="部署ID" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <el-form-item label="key" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <el-form-item label="版本" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <el-form-item> 
        <el-button type="primary" @click="onSubmit('editForm')">保存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import { activeUrl } from "@/config/env";
const urls = {
  save: activeUrl + "/dict/sys-dict/edit",
  list: activeUrl + "/activitDefineList",
  get: activeUrl + "/dict/sys-dict/edit_form",
};
export default {
  data() {
    return {
      dialogVisible: false,
      data: [],
      form: {
        value: null,
        note: null,
      },
      rules: {
        uname: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          //{
            // validator: (rule, value, callback) => {
              // axios
              //   .get(urls.checkField, {
              //     params: {
              //       table: "t_user",
              //       field: "uname",
              //       value: value,
              //       kid: this.form.kid
              //     }
              //   })
              //   .then(res => {
              //     if (res.data.result) {
              //       callback("用户名必须唯一");
              //     } else {
              //       callback();
              //     }
              //   });
            // },
            //trigger: "blur"
         // }
        ]
        // name: [{ required: true, message: "请输入用户姓名", trigger: "blur" }]
      }
    };
  },
  components: {},
  methods: {
    show(objectId) {
      
      this.dialogVisible = true;
      if (this.$refs["editForm"]) {
        this.$refs["editForm"].resetFields();
      }
      this.fetch(objectId);
    },
    onSubmit(formName) {
      // this.$refs[formName].validate(valid => {
      //   if (valid) {
          
          axios.post(urls.save, this.form).then(res => {
            this.$message(res.data.result);
            this.dialogVisible = false;
            this.$emit("refresh");
          });
      //   }
      //   return false;
      // });
    },
    fetch(objectId) {
      axios.get(urls.get, { params: { objectId: objectId } }).then(res => {
        let data = res.data.result;
        this.form = {
          objectId: data.objectId,
          value: data.value,
          note : data.note
        };
      });
      axios.post(urls.list,{status : 0}).then(res => {
        this.data = res.data.result.records;
      });
    }
  },
};
</script>